package com.dubo.film.exhibition.controller;

import com.dubo.film.model.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import wog.dubo.business.user.model.UserFilm;
import wog.dubo.business.user.service.UserFilmService;

import javax.servlet.http.HttpServletRequest;
import java.util.logging.Logger;

/**
 * 登陆控制器
 * author WC
 * time 2017/9/9
 * project : filmWeb
 */
@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private UserFilmService userFilmService;

    private Logger logger;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String login(HttpServletRequest request){
        try {
            request.setAttribute("name","woc");
            return "/index";
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.print("12354");
        return null;
    }



    /**
     *
     * @param userFilm
     * @return
     */

    public ResponseModel userLogin(UserFilm userFilm){
        try {
            UserFilm user = userFilmService.gettUserByUserName(userFilm.getUserName());
            if (user.getPassword().equals(userFilm.getPassword())) {
                return ResponseModel.returnModel(0, "登陆成功");
            } else {
                ResponseModel.returnModel(1, "登陆失败，密码错误");
            }
        }catch (Exception e){
            logger.info("发生未知错误");
        }
        return ResponseModel.returnModel(1,"发生未知错误");
    }





}
